import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from "../views/main.vue"
import Login from "../views/Login"
import CategoryEdit from "../views/CategoryEdit.vue"
import CategoryList from "../views/CategoryList.vue"
import CategoryCreate from "../views/CategoryCreate.vue"
import ItemEdit from "../views/itemEdit"
import ItemList from "../views/itemList"
import HeroEdit from "../views/heroEdit"
import HeroList from "../views/heroList"
import ArticleEdit from "../views/ArticleEdit"
import ArticleList from "../views/ArticleList"
import AdEdit from "../views/AdEdit"
import AdList from "../views/AdList"
import AdminUserEdit from "../views/AdminUserEdit"
import AdminUserList from "../views/AdminUserList"

import ShiYanList from "../views/shiyan"

Vue.use(VueRouter)

const router = new VueRouter({

  routes: [{
      path: '/',
      name: 'main',
      component: Main,
      children: [{
          path: "/categoires/create",
          component: CategoryCreate
        },
        {
          path: "/categoires/edit/:id",
          component: CategoryEdit,
          props: true
        },
        {
          path: "/categoires/list",
          component: CategoryList
        },

        {
          path: "/items/create",
          component: ItemEdit
        },
        {
          path: "/items/edit/:id",
          component: ItemEdit,
          props: true
        },
        {
          path: "/items/list",
          component: ItemList
        },

        {
          path: "/heroes/create",
          component: HeroEdit
        },
        {
          path: "/heroes/edit/:id",
          component: HeroEdit,
          props: true
        },
        {
          path: "/heroes/list",
          component: HeroList
        },

        {
          path: "/articles/create",
          component: ArticleEdit
        },
        {
          path: "/articles/edit/:id",
          component: ArticleEdit,
          props: true
        },
        {
          path: "/articles/list",
          component: ArticleList
        },

        {
          path: "/ads/create",
          component: AdEdit
        },
        {
          path: "/ads/edit/:id",
          component: AdEdit,
          props: true
        },
        {
          path: "/ads/list",
          component: AdList
        },

        {
          path: "/admin_users/create",
          component: AdminUserEdit
        },
        {
          path: "/admin_users/edit/:id",
          component: AdminUserEdit,
          props: true
        },
        {
          path: "/admin_users/list",
          component: AdminUserList
        },
        {
          path: "/shiyan/list",
          component: ShiYanList
        },
      ]
    },
    {
      path: "/login",
      name: "login",
      component: Login,
      meta: {
        isPublic: true
      }
    }
  ]
})




router.beforeEach((to, from, next) => {
  if (!to.meta.isPublic && !localStorage.token) {
    return next("/login")
  }
  next()
})

export default router